function GSLevel () {
	var chapter = 0;
	var levelImageHandle = [];
	
	
	var UNLOCKED_SX = 0;
	var UNLOCKED_SY = 0;
	var UNLOCKED_CLICKED_SX = 50;
	var UNLOCKED_CLICKED_SY = 0;
	var PASSED_SX = 100;
	var PASSED_SY = 0;
	var PASSED_CLICKED_SX = 150;
	var PASSED_CLICKED_SY = 0;
	var LOCKED_SX = 200;
	var LOCKED_SY = 0;
	
	var FLAG_W = 50;
	var FLAG_H = 50;

	var iconX;
	var iconY;
	
	var progress = 5;
	var selecting = -1;
	var mouseStatus = 0;
	
	
	
	// Button
	var BACK_BUTTON_SXU = 0;
	var BACK_BUTTON_SYU = 0;
	var BACK_BUTTON_SXD = 0;
	var BACK_BUTTON_SYD = 150;
	var BACK_BUTTON_SW = 150;
	var BACK_BUTTON_SH = 150;
	
	var BACK_BUTTON_DX = 1125;
	var BACK_BUTTON_DY = 555;
	var BACK_BUTTON_DW = 150;
	var BACK_BUTTON_DH = 150;
	
	var backButton;
	
	this.Init = function () {
		for (var i=0; i<4; i++) {
			levelImageHandle[i] = g_graphicEngine.LoadImage("Data/MainMenu/GSLevel/Chapter " + (i + 1) + ".jpg");
		}
		flagIconHandle = g_graphicEngine.LoadImage("Data/MainMenu/GSLevel/Flags.png");
		
		backButton = new Button();
		backButton.LoadImage("Data/MainMenu/BackButton.png", BACK_BUTTON_SXU, BACK_BUTTON_SYU, BACK_BUTTON_SXD, BACK_BUTTON_SYD, BACK_BUTTON_SW, BACK_BUTTON_SH);
		backButton.SetPosition (BACK_BUTTON_DX, BACK_BUTTON_DY, BACK_BUTTON_DW, BACK_BUTTON_DH);
		backButton.RegisterFunction(BackToChapter);
	}
	
	this.Update = function () {
	
	}
	
	this.Draw = function () {
		g_graphicEngine.DrawFast (g_context, levelImageHandle[chapter], 0, 0);
		
		for (var i=0; i<progress; i++) {
			if (selecting == i) {
				g_graphicEngine.Draw (g_context, flagIconHandle, PASSED_CLICKED_SX, PASSED_CLICKED_SY, FLAG_W, FLAG_H, iconX[i], iconY[i], FLAG_W, FLAG_H);
			}
			else {
				g_graphicEngine.Draw (g_context, flagIconHandle, PASSED_SX, PASSED_SY, FLAG_W, FLAG_H, iconX[i], iconY[i], FLAG_W, FLAG_H);
			}
		}
		
		if (selecting == progress) {
			g_graphicEngine.Draw (g_context, flagIconHandle, UNLOCKED_CLICKED_SX, UNLOCKED_CLICKED_SY, FLAG_W, FLAG_H, iconX[i], iconY[i], FLAG_W, FLAG_H);
		}
		else {
			g_graphicEngine.Draw (g_context, flagIconHandle, UNLOCKED_SX, UNLOCKED_SY, FLAG_W, FLAG_H, iconX[i], iconY[i], FLAG_W, FLAG_H);
		}

		for (var i=progress+1; i<iconX.length; i++) {
			g_graphicEngine.Draw (g_context, flagIconHandle, LOCKED_SX, LOCKED_SY, FLAG_W, FLAG_H, iconX[i], iconY[i], FLAG_W, FLAG_H);
			console.log (i);
		}
		
		backButton.Draw();
	}
	
	this.OnSwitch = function () {
		
	}
	
	this.OnMouseMove = function (x, y) {
		if (mouseStatus == 1) {
			selecting = -1;
			for (var i=0; i<iconX.length; i++) {
				if (x >= iconX[i] && x <= iconX[i] + FLAG_W && y >= iconY[i] && y <= iconY[i] + FLAG_H) {
					selecting = i;
					break;
				}
			}
		}
		
		backButton.OnMouseMove (x, y);
	}
	
	this.OnMouseDown = function (x, y) {
		mouseStatus = 1;
		selecting = -1;
		for (var i=0; i<iconX.length; i++) {
			if (x >= iconX[i] && x <= iconX[i] + FLAG_W && y >= iconY[i] && y <= iconY[i] + FLAG_H) {
				selecting = i;
				break;
			}
		}
		
		backButton.OnMouseDown (x, y);
	}
	
	this.OnMouseUp = function (x, y) {
		mouseStatus = 0;
		
		if (selecting > -1 && selecting <= progress) {
			StartMatch (chapter + 1, selecting);
			selecting = -1;
		}
		
		backButton.OnMouseUp (x, y);
	}
	
	this.OnMouseWheel = function (delta) {
	
	}
	
	this.OnKeyDown = function (keycode) {
	
	}
	
	this.OnKeyUp = function (keycode) {
	
	}
	
	this.ChapterSelected = function (c) {
		chapter = c - 1;
		
		if (chapter == 0) {
			iconX = [249, 343, 436, 539, 642, 753, 844, 949, 1050, 1089, 1033, 1033, 928, 823, 703, 586, 465, 367, 248, 156];
			iconY = [111, 126, 160, 167, 146, 133, 184, 213, 232 , 330 , 408 , 520 , 546, 485, 500, 544, 534, 470, 453, 392];
		}
		else if (chapter == 1) {
			iconX = [259, 315, 417, 526, 631, 746, 847, 952, 998, 1002, 959, 860, 750, 643];
			iconY = [137, 171, 188, 193, 167, 151, 149, 185, 299, 417,  518, 515, 515, 544];
		}
		
		if (c == g_userProfile.m_chapter) {
			progress = g_userProfile.m_level;
		}
		else {
			progress = iconX.length;
		}
	}
	
	var StartMatch = function (chapter, level) {
		g_gsGamePlay.Init(chapter, level);
		SwitchState (g_gsGamePlay, true);
	}
	
	var BackToChapter = function () {
		SwitchState (g_gsChapter, true);
	}
}